from typing import Optional, Tuple

from django.db.models import QuerySet

from server.apps.todo.logic.jobs import commands, queries, validation
from server.apps.todo.models import ToDo


def run(
    title: Optional[str],
    description: Optional[str],
    done: Optional[bool],
) -> Tuple[bool, QuerySet[ToDo]]:
    """Validates data, maybe creates a new job."""
    validated_data = validation.validate(
        title=title,
        description=description,
        done=done,
    )
    if validated_data:
        commands.create(validated_data)

    return validated_data is not None
